package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TRider;
import com.ruoyi.system.service.ITRiderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 骑手信息Controller
 * 
 * @author ruoyi
 * @date 2024-02-04
 */
@RestController
@RequestMapping("/system/rider")
public class TRiderController extends BaseController
{
    @Autowired
    private ITRiderService tRiderService;

    /**
     * 查询骑手信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:rider:list')")
    @GetMapping("/list")
    public TableDataInfo list(TRider tRider)
    {
        startPage();
        List<TRider> list = tRiderService.selectTRiderList(tRider);
        return getDataTable(list);
    }

    /**
     * 导出骑手信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:rider:export')")
    @Log(title = "骑手信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRider tRider)
    {
        List<TRider> list = tRiderService.selectTRiderList(tRider);
        ExcelUtil<TRider> util = new ExcelUtil<TRider>(TRider.class);
        util.exportExcel(response, list, "骑手信息数据");
    }

    /**
     * 获取骑手信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rider:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(tRiderService.selectTRiderByID(ID));
    }

    /**
     * 新增骑手信息
     */
    @PreAuthorize("@ss.hasPermi('system:rider:add')")
    @Log(title = "骑手信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TRider tRider)
    {
        return toAjax(tRiderService.insertTRider(tRider));
    }

    /**
     * 修改骑手信息
     */
    @PreAuthorize("@ss.hasPermi('system:rider:edit')")
    @Log(title = "骑手信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TRider tRider)
    {
        return toAjax(tRiderService.updateTRider(tRider));
    }

    /**
     * 删除骑手信息
     */
    @PreAuthorize("@ss.hasPermi('system:rider:remove')")
    @Log(title = "骑手信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        return toAjax(tRiderService.deleteTRiderByIDs(IDs));
    }
}
